#include <iostream>
#include <string>
#include "DoubleLinkedList.h"

using namespace std;

DoubleLinkedList<double>::iterator find(DoubleLinkedList<double>& _list, double  _val )
{
    DoubleLinkedList<double>::iterator iter = _list.begin();
    while(iter!=_list.end())
    {
        if(*iter == _val) 
		    {return iter;}
		++iter;
    }
    if(iter==_list.end())
        cout << "The value entered in the function Find is not found." << endl;
}


int main()
{
	DoubleLinkedList<double> L;

	L.push_back(1);
	L.push_back(2);
	L.push_back(3);
	L.push_back(4);
	L.push_back(5);

	DoubleLinkedList<double>::iterator iter = L.begin();

	while(iter != L.end())
	{
    	cout << *iter << " ";
	    ++iter;
	}
    cout << endl;

    iter = find(L,3);
	L.erase(iter);
    iter = L.begin();
	while(iter != L.end())
	{
    	cout << *iter << " ";
	    ++iter;
	}
	cout << endl;

    iter = find(L,3);

    L.pop_front();
	L.push_front(0);
	L.pop_back();
	L.push_back(10);

	iter = L.begin();
	while(iter != L.end())
	{
    	cout << *iter << " ";
	    ++iter;
	}
    cout << endl;
	cout << "The current size of the list is " << L.size() << endl;

    L.clear();


    for(double i=0.5;i<=5.0;i=i+0.5)
	{
		L.push_back(i);
	}

	iter = L.begin();
    while(iter != L.end())
	{
    	cout << *iter << " ";
	    ++iter;
	}
    cout << endl;

    iter = find(L,2.5);
	iter = L.insert(iter,2.0);
	iter++;

	DoubleLinkedList<double>::iterator iter1 = find(L,4);
	iter = L.erase(iter,iter1);

	iter = L.begin();
	while(iter != L.end())
	{
    	cout << *iter << " ";
	    ++iter;
	}
	cout << endl;
   	cout << "The current size of the list is " << L.size() << endl; 
    
	try{
	    DoubleLinkedList<double>::iterator iter2;
        L.erase(iter2);
	}

	catch(char const* t){
		cout << t << endl;
	}

	try{
		DoubleLinkedList<double>::iterator iter2;
        DoubleLinkedList<double> L1;
		for(int i=0;i<5;i++){
			L1.push_back(i);
		}
		iter2 = find(L1,3);
		L.erase(iter2);
	}
	
	catch(char const* p){
		cout << p << endl;
	}


	return 0;
}